added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / VBASPNETSerializeJsonString / AutoComplete.ashx.vb
blob2c7f74da224b319adb06e8217ed162656c156cc1
1 '/****************************** Module Header ******************************\
2 '* Module Name: AutoComplete.ashx.vb
3 '* Project: VBASPNETSerializeJsonString
4 '* Copyright (c) Microsoft Corporation
5 '*
6 '* This project illustrates how to serialize Json string. we use jQuery at client
7 '* side and manipulate XML data at server side.
8 '* It demonstrates how to use the serializable json data through an autocomplete
9 '* example.
10 '*
11 '* This source is subject to the Microsoft Public License.
12 '* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
13 '* All other rights reserved.
15 '\*****************************************************************************/
17 Imports System.Web
18 Imports System.Web.Services
19 Imports System.Web.Script.Serialization
20 Imports System.Data
23 Public Class AutoComplete
24 Implements System.Web.IHttpHandler
26 Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
28 ' Query string 'term' is for autocomplete. By default, it sends the variable
29 ' "term" with the search word to the backend page.
30 Dim searchText As String = context.Request.QueryString("term")
31 Dim books As Collection = New Collection
33 Dim ds As New DataSet()
34 ds.ReadXml(HttpContext.Current.Server.MapPath("App_Data/books.xml"))
35 Dim dv As DataView = ds.Tables(0).DefaultView
36 dv.RowFilter = [String].Format("title like '{0}*'", searchText.Replace("'", "''"))
38 Dim book As Book
39 For Each myDataRow As DataRowView In dv
40 book = New Book()
41 book.id = myDataRow("id").ToString()
42 book.value = myDataRow("title").ToString()
43 book.label = myDataRow("title").ToString()
44 book.Author = myDataRow("author").ToString()
45 book.Genre = myDataRow("genre").ToString()
46 book.Price = myDataRow("price").ToString()
47 book.Publish_date = myDataRow("publish_date").ToString()
48 book.Description = myDataRow("description").ToString()
49 books.Add(book)
50 Next
52 Dim serializer As JavaScriptSerializer = New JavaScriptSerializer
53 Dim jsonString As String = serializer.Serialize(books)
54 context.Response.Write(jsonString)
56 End Sub
58 ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
59 Get
60 Return False
61 End Get
62 End Property
65 End Class